package com.gupao.javavip.gof.proxy.dynamicproxy;

import java.lang.reflect.Method;

public class ControllerDynamicAddition implements MyInvocationHandler {

    private Object controller;//需要代理的目标对象

    public Object newProxy(Object controller) {//将目标对象传入进行代理
        this.controller = controller;
        return MyProxy.newProxyInstance(new MyClassLoader(),
                controller.getClass().getInterfaces(), this);//返回代理对象
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("收到请求：" + args[0]);
        Object result = method.invoke(controller, args);
        System.out.println("请求处理完成");
        return result;
    }
}
